{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 配置静态文件\n",
    "\n",
    "from tornado.web import StaticFileHandler, RedirectHandler\n",
    "from tornado import web\n",
    "import tornado\n",
    "import time\n",
    "\n",
    "\n",
    "class MainHandler(web.RequestHandler):\n",
    "    async def get(self, *args, **kwargs):\n",
    "        time.sleep(5)\n",
    "        self.write(\"hello world\")\n",
    "\n",
    "\n",
    "class MainHandler2(web.RequestHandler):\n",
    "    async def get(self, *args, **kwargs):\n",
    "        self.write(\"hello world2\")\n",
    "\n",
    "## 静态文件访问路径配置\n",
    "## 方法1\n",
    "settings = {\n",
    "    ## 静态文件的路径\n",
    "    \"static_path\": \"/Users/dengjun/Develop/python/tornado_demo/static\",\n",
    "    ## 静态文件的\n",
    "    \"static_url_prefix\": \"/static/\",\n",
    "}\n",
    "\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    app = web.Application([\n",
    "        (\"/\", MainHandler),\n",
    "        (\"/2/\", RedirectHandler, {\"url\": \"/\"}),\n",
    "        ## 静态文件访问路径配置\n",
    "        ## 方法2\n",
    "        (\"/static3/(.*)\", StaticFileHandler, {\"path\": \"/Users/dengjun/Develop/python/tornado_demo/static\"})\n",
    "    ], debug=True, **settings)\n",
    "\n",
    "    app.listen(8000)\n",
    "    tornado.ioloop.IOLoop.current().start()\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
